package com.aspose.cells;

import java.util.Arrays;

class zsg {
   private boolean g;
   private long h;
   private short i;
   private int j;
   zamp a;
   short[] b;
   byte[] c;
   private zbqk k;
   byte[] d;
   byte[] e;
   String f;

   public static zsg a() {
      byte[] var0 = new byte[]{21, 122, 103, 84, 81, 87, 50, 85, 62, 80, 120, 119, 24, 18, -76, -125};
      byte[] var1 = new byte[]{124, 52, -52, 7, -95, 117, -109, -128, -76, -68, -1, 58, 124, -41, 52, -70};
      byte[] var2 = new byte[]{-22, 87, 79, -87, -77, 114, 80, 50, -71, 103, 111, 80, 29, 110, 25, 46};
      return new zsg("VelvetSweatshop", var0, var1, var2);
   }

   public zsg(String var1, byte[] var2, byte[] var3, byte[] var4) {
      if (var2.length == 16 && var3.length == 16 && var4.length == 16) {
         if (var1.length() != 0 && var1.length() <= 15) {
            this.i = 0;
            this.g = false;
            this.h = 4294967295L;
            this.k = new zbqk();
            this.b = new short[16];
            this.c = new byte[16];
            this.a = new zamp();
            this.j = 1024;
            this.a(var1, var2, var3, var4);
            this.f = var1;
         } else {
            throw new IllegalArgumentException("Invalid password length: should be 1-15 characters.");
         }
      } else {
         throw new IllegalArgumentException();
      }
   }

   public zsg(String var1, byte[] var2, byte[] var3, byte[] var4, int var5) {
      if (var2.length == 16 && var3.length == 16 && var4.length == 16) {
         if (var1.length() != 0 && var1.length() <= 15) {
            this.i = 0;
            this.g = false;
            this.h = 4294967295L;
            this.k = new zbqk();
            this.b = new short[16];
            this.c = new byte[16];
            this.a = new zamp();
            this.j = var5;
            this.a(var1, var2, var3, var4);
            this.f = var1;
         } else {
            throw new IllegalArgumentException("Invalid password length: should be 1-15 characters.");
         }
      } else {
         throw new IllegalArgumentException();
      }
   }

   public byte[] b() {
      return this.c;
   }

   private void a(zbqk var1, short var2) {
      if (this.g) {
         int var3 = var1.a();
         if (this.h != (long)var3 || this.i != var2) {
            this.a(this.h, (long)var3, var2);
            this.h = (long)var3;
            this.i = var2;
         }
      }

   }

   public byte[] a(byte[] var1, int var2, int var3, long var4) {
      if (var1 != null && var3 > 0 && var2 + var3 <= var1.length) {
         byte[] var6 = new byte[var3];
         this.k.a(var1, (short)var2, (int)var4);
         if (this.g) {
            this.a(this.k, this.i);
            this.a(this.k, var6, (short)var3);
            this.h = (long)this.k.a();
         } else {
            this.k.a(var6, (int)0, var3);
         }

         return var6;
      } else {
         throw new IllegalArgumentException();
      }
   }

   private void a(long var1, long var3, short var5) {
      if (var3 != var1) {
         int var6 = this.a(var1);
         short var7 = this.b(var1);
         int var8 = this.a(var3);
         short var9 = this.b(var3);
         if (var8 != var6 || var9 < var7) {
            this.a.a(var8);
            var7 = 0;
         }

         if (var9 > var7) {
            this.a.b(var9 - var7);
         }
      }

   }

   private short a(zbqk var1, byte[] var2, short var3) {
      short var4 = 0;
      short var5 = 0;

      short var8;
      for(short var6 = var3; var6 > 0; var6 -= var8) {
         short var7 = (short)(this.j - this.b((long)var1.a()));
         var8 = (short)Math.min(var6, var7);
         var4 += (short)var1.a(var2, (int)var5, var8);
         this.a.a(var2, var5, var8, var2, var5, var8);
         if (this.b((long)var1.a()) == 0) {
            this.a.a(this.a((long)var1.a()));
         }

         var5 += var8;
      }

      return var4;
   }

   private void a(String var1, byte[] var2, byte[] var3, byte[] var4) {
      com.aspose.cells.a.e.zf.a(var2.length == 16 && var3.length == 16 && var4.length == 16);
      int var5 = var1.length();
      Arrays.fill(this.b, (short)0);

      int var6;
      for(var6 = 0; var6 < var5; ++var6) {
         this.b[var6] = (short)var1.charAt(var6);
      }

      for(var6 = 0; var6 < var2.length; ++var6) {
         this.c[var6] = var2[var6];
      }

      this.a.a(this.b, this.c);
      this.a.b(var3, var4);
      this.d = var3;
      this.e = var4;
      this.g = true;
   }

   private int a(long var1) {
      return (int)(var1 / (long)this.j);
   }

   private short b(long var1) {
      return (short)((int)(var1 % (long)this.j));
   }
}
